/*     */ package com.hs.activation.controller;
/*     */ 
/*     */ import com.baomidou.mybatisplus.core.conditions.Wrapper;
/*     */ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
/*     */ import com.baomidou.mybatisplus.core.metadata.IPage;
/*     */ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/*     */ import com.hs.activation.common.annotation.PassToken;
/*     */ import com.hs.activation.common.result.BaseController;
/*     */ import com.hs.activation.common.result.Result;
/*     */ import com.hs.activation.common.utils.BaseUtil;
/*     */ import com.hs.activation.entity.User;
/*     */ import com.hs.activation.service.IUserService;
/*     */ import com.hs.activation.vo.UserLoginVO;
/*     */ import com.hs.activation.vo.UserResetPasswordVO;
/*     */ import io.swagger.annotations.Api;
/*     */ import io.swagger.annotations.ApiOperation;
/*     */ import io.swagger.annotations.ApiParam;
/*     */ import java.lang.invoke.SerializedLambda;
/*     */ import javax.annotation.Resource;
/*     */ import org.springframework.util.DigestUtils;
/*     */ import org.springframework.web.bind.annotation.DeleteMapping;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.PutMapping;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.RestController;
/*     */ 
/*     */ @RestController
/*     */ @RequestMapping({"user"})
/*     */ @Api(value = "用户信息接口", tags = {"用户信息接口"})
/*     */ public class UserController extends BaseController {
/*     */   @Resource
/*     */   private IUserService userService;
/*     */   
/*     */   @ApiOperation(value = "获取用户信息", notes = "获取用户信息", httpMethod = "GET")
/*     */   @GetMapping
/*     */   public Result list(@ApiParam("查询条件") String key) {
/*  40 */     LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper();
/*  41 */     if (!BaseUtil.isEmpty(key)) {
/*  42 */       queryWrapper.like(User::getUserName, key);
/*     */     }
/*  44 */     return ok(this.userService.list((Wrapper)queryWrapper));
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   @ApiOperation(value = "获取用户信息", notes = "获取用户信息-分页", httpMethod = "GET")
/*     */   @GetMapping({"/{current}/{size}"})
/*     */   public Result list(@PathVariable @ApiParam(value = "当前页", required = true) Long current, @PathVariable @ApiParam(value = "每页个数", required = true) Long size, @ApiParam("查询条件") String key) {
/*  52 */     LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper();
/*  53 */     if (!BaseUtil.isEmpty(key)) {
/*  54 */       queryWrapper.like(User::getUserName, key);
/*     */     }
/*  56 */     Page<User> page = new Page(current.longValue(), size.longValue());
/*  57 */     return ok(this.userService.page((IPage)page, (Wrapper)queryWrapper));
/*     */   }
/*     */ 
/*     */   
/*     */   @ApiOperation(value = "获取用户信息", notes = "根据ID获取用户信息", httpMethod = "GET")
/*     */   @GetMapping({"/{id}"})
/*     */   public Result findById(@PathVariable @ApiParam(value = "当前页", required = true) Integer id) {
/*  64 */     return ok(this.userService.getById(id));
/*     */   }
/*     */ 
/*     */   
/*     */   @DeleteMapping({"/{id}"})
/*     */   @ApiOperation(value = "删除用户信息", notes = "根据id删除用户信息", httpMethod = "DELETE")
/*     */   public Result deleteById(@PathVariable @ApiParam("ID") Integer id) {
/*  71 */     return ok(Boolean.valueOf(this.userService.removeById(id)));
/*     */   }
/*     */   
/*     */   @PostMapping({""})
/*     */   @ApiOperation(value = "保存用户信息", notes = "新增一条保存信息", httpMethod = "POST")
/*     */   public Result save(@RequestBody User user) {
/*  77 */     user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
/*  78 */     if (this.userService.save(user)) {
/*  79 */       return ok();
/*     */     }
/*  81 */     return fail();
/*     */   }
/*     */ 
/*     */   
/*     */   @PutMapping({""})
/*     */   @ApiOperation(value = "保存用户信息", notes = "更新保存信息", httpMethod = "PUT")
/*     */   public Result update(@RequestBody User user) {
/*  88 */     user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
/*  89 */     if (this.userService.updateById(user)) {
/*  90 */       return ok();
/*     */     }
/*  92 */     return fail();
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   @PostMapping({"/login"})
/*     */   @PassToken
/*     */   @ApiOperation(value = "用户登陆", notes = "用户登陆", httpMethod = "POST")
/*     */   public Result login(@RequestBody UserLoginVO login) {
/*     */     try {
/* 102 */       return this.userService.login(login);
/* 103 */     } catch (Exception ee) {
/* 104 */       return fail(ee.getMessage());
/*     */     } 
/*     */   }
/*     */   
/*     */   @PostMapping({"/getuser/{token}"})
/*     */   @ApiOperation(value = "获取用户信息", notes = "获取用户信息", httpMethod = "GET")
/*     */   public Result getUser(@PathVariable String token) {
/* 111 */     return new Result("查询成功", Integer.valueOf(200), this.userService.getUser(token));
/*     */   }
/*     */   @PostMapping({"/reset_password"})
/*     */   @ApiOperation(value = "重制用户密码", notes = "重制用户密码", httpMethod = "POST")
/*     */   public Result resetPassword(@RequestBody UserResetPasswordVO resetPasswordVO) {
/* 116 */     if (this.userService.resetPassword(resetPasswordVO)) {
/* 117 */       return ok("重制成功");
/*     */     }
/* 119 */     return fail("重制失败");
/*     */   }
/*     */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\controller\UserController.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */